/*
* Copyright 2017 Yonyou Auto Information Technology（Shanghai） Co., Ltd. All Rights Reserved.
*
* This software is published under the terms of the YONYOU Software
* License version 1.0, a copy of which has been included with this
* distribution in the LICENSE.txt file.
*
* @Project Name : marketing-service-customer
*
* @File name : CustomerController.java
*
* @Author : Administrator
*
* @Date : 2017年3月8日
*
----------------------------------------------------------------------------------
*     Date       Who       Version     Comments
* 1. 2017年3月8日    Administrator    1.0
*
*
*
*
----------------------------------------------------------------------------------
*/

package com.yonyou.gmmc.service.customer.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.apache.log4j.Logger;
import org.marketing.common.Response;
import org.marketing.common.constants.CommonConstant;
import org.marketing.common.constants.ResultMsgConstants;
import org.marketing.common.dto.MQReceiveResult;
import org.marketing.common.dto.carOwner.CarOwnerDto;
import org.marketing.common.dto.customerInfo.CarInfoDto;
import org.marketing.common.dto.customerInfo.CounselorDto;
import org.marketing.common.dto.customerInfo.MemberDto;
import org.marketing.common.dto.leads.InsuranceDto;
import org.marketing.common.event.BizEvent;
import org.marketing.common.util.CheckUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.yonyou.gmmc.service.customer.constant.CustomerInfoConstant;
import com.yonyou.gmmc.service.customer.entity.PointsChangePO;
import com.yonyou.gmmc.service.customer.entity.TmDealer;
import com.yonyou.gmmc.service.customer.entity.TtWebpageLog;
import com.yonyou.gmmc.service.customer.entity.WebpageLogPo;
import com.yonyou.gmmc.service.customer.model.TtComplaint;
import com.yonyou.gmmc.service.customer.service.CustomerService;
import com.yonyou.gmmc.service.customer.service.WebpageLogService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author Administrator
 * @date 2017年3月8日counselors
 */
@RestController
@RequestMapping(value = CustomerInfoConstant.BASE_PATH + "/" + CustomerInfoConstant.VERSION)
@Api("客户信息API")
public class CustomerController {

	private Logger logger = Logger.getLogger(CustomerController.class);
	@Autowired
	private CustomerService customerService;

	@Autowired
	private WebpageLogService webpageLogService;

	@RequestMapping(value = "/fans", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "判断是否为粉丝信息", notes = "判断是否为粉丝信息")
	public Response<Map<String, Object>> queryFans(HttpServletRequest request) {
		String openId = request.getHeader(CommonConstant.HEADER_OPENID);
		try {
			logger.info("我的OPENID为：" + openId);
			Map<String, Object> result = customerService.queryFans(openId);
			return new Response<Map<String, Object>>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询发生异常", e);
			return new Response<Map<String, Object>>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 判断是否为车主
	 * 
	 * @author Administrator
	 * @date 2017年3月18日
	 * @param request
	 * @return 车主信息
	 */
	@RequestMapping(value = "/queryUserOwner", method = RequestMethod.GET)
	@ApiOperation(value = "判断是否为车主", notes = "判断是否为车主")
	public Response<List<MemberDto>> queryUserOwner(HttpServletRequest request) {
		logger.info("CustomerController.queryUserOwner==>start...");
		try {
			String userId = request.getHeader(CommonConstant.HEAD_USER_ID);
			logger.info("我的userId为：" + userId);
			List<MemberDto> result = customerService.queryUserOwner(userId);
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		} finally {
			logger.info("CustomerController.queryUserOwner==>end...");
		}
	}
	
	/**
	 * 判断是否为车主
	 * 
	 * @author Administrator
	 * @date 2017年3月18日
	 * @param request
	 * @return 车主信息
	 */
	/*@RequestMapping(value = "/queryUserOwner", method = RequestMethod.GET)
	@ApiOperation(value = "判断是否为车主", notes = "判断是否为车主")
	public List<MemberDto> queryUserOwner(HttpServletRequest request) {
		logger.info("CustomerController.queryUserOwner==>start...");
		String userId = request.getHeader(CommonConstant.HEAD_USER_ID);
		logger.info("我的userId为：" + userId);
		List<MemberDto> result = customerService.queryUserOwner(userId);
		return result;
	}*/
	
	/**
     * 判断是否为车主
     * 
     * @author Administrator
     * @date 2017年3月18日
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/queryUserOwner2", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "判断是否为车主", notes = "判断是否为车主")
    public Response<List<MemberDto>> queryUserOwner2(HttpServletRequest request) throws Exception {
        try{
	    	String openId = request.getHeader(CustomerInfoConstant.HEADER_OPENID);
	        // String openId= "oXrcfuEiiI3K153hiEdTol4wWbqw";
	        logger.info("我的OPENID为：" + openId);
	        List<MemberDto> dtoList = customerService.queryUserOwner2(openId);
	        return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, dtoList, "");
	    } catch (Exception e) {
			logger.error("查询发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		} finally {
			logger.info("CustomerController.queryUserOwner==>end...");
		}
    }

	/**
	 * 会员中心信息查询
	 * 
	 * @author QianKun
	 * @date 2017年2月28日
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/memberInfo", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "查询车主信息", notes = "查询车主信息")
	public Response<List<MemberDto>> getMemberInfo(HttpServletRequest request) {
		logger.info("CustomerController.getMemberInfo==>start...");
		try {
			String userId = request.getHeader(CommonConstant.HEAD_USER_ID);
			logger.info("我的userId为：" + userId);
			List<MemberDto> dtoList = customerService.getMemberInfo(userId);
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, dtoList, "");
		} catch (Exception e) {
			logger.error("查询发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		} finally {
			logger.info("CustomerController.getMemberInfo==>end...");
		}
	}

	/**
	 * 潜客信息查询
	 * 
	 * @author QianKun
	 * @date 2017年3月16日
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/potentialInfo", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "潜客信息查询", notes = "潜客信息查询")
	public List<MemberDto> getPotentialInfo(HttpServletRequest request) {
		String openId = request.getHeader(CommonConstant.HEADER_OPENID);
		// String openId= "oXrcfuGP_a3daNZaMT_rbhvJ595I";
		logger.info("进入controller,opid为" + openId);
		List<MemberDto> dtoList = customerService.getPotentialInfo(openId);
		return dtoList;
	}
	/**
	 * @param request
	 * @return
	 */
	public List<MemberDto> getPotentialInfo1(HttpServletRequest request) {
		String openId = request.getHeader(CommonConstant.HEADER_OPENID);
		// String openId= "oXrcfuGP_a3daNZaMT_rbhvJ595I";
		logger.info("进入controller,opid为" + openId);
		List<MemberDto> dtoList = customerService.getPotentialInfo(openId);
		return dtoList;
	}
	/**
	 * 更新会员信息(车主)
	 * 
	 * @author QianKun
	 * @date 2017年3月1日
	 * @param memberDto
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/updateCarOwnerInfo", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "更新会员信息(车主)", notes = "更新会员信息(车主)")
	public @ResponseBody Map<String, Object> updateCarOwnerInfo(@RequestBody @Valid MemberDto memberDto)
			throws Exception {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap = customerService.updateCarOwnerInfo(memberDto);
		// resultMap.put(ResultMsgConstants.RESULT_CODE,
		// ResultMsgConstants.RESULT_CODE_SUCCESS);
		return resultMap;
	}

	/**
	 * 更新会员信息(潜客)
	 * 
	 * @author QianKun
	 * @date 2017年3月1日
	 * @param memberDto
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/updatePotentialInfo", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "更新会员信息(潜客)", notes = "更新会员信息(潜客)")
	public @ResponseBody Map<String, Object> updatePotentialInfo(@RequestBody @Valid MemberDto memberDto,
			HttpServletRequest request) {
		String openId = request.getHeader(CommonConstant.HEADER_OPENID);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap = customerService.updatePotentialInfo(memberDto, openId);
		return resultMap;
	}

	/**
	 * 更新会员信息(顾问)
	 * 
	 * @author QianKun
	 * @date 2017年3月1日
	 * @param memberDto
	 * @return
	 */
	@RequestMapping(value = "/updateCounselorInfo", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "更新会员信息(顾问)", notes = "更新会员信息(顾问)")
	public @ResponseBody Map<String, Object> updateCounselorInfo(@RequestBody @Valid MemberDto memberDto,
			HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String openId = request.getHeader(CommonConstant.HEADER_OPENID);
		resultMap = customerService.updateCounselorInfo(memberDto, openId);
		return resultMap;
	}

	/**
	 * 注册会员(车主)
	 * 
	 * @author QianKun
	 * @date 2017年3月8日
	 * @param memberDto
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@RequestMapping(value = "/insertCarOwner", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "注册会员(车主)", notes = "注册会员(车主)")
	public @ResponseBody Response insertCarOwner(@RequestBody @Valid CarOwnerDto CarOwnerDto,
			@RequestParam(value = "openId", required = false, defaultValue = "") String openId_,
			HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<>();
		String openId = "";
		try {
			if (!CheckUtil.NullOrEmpty(openId_)) {
				openId = openId_;
			} else {
				openId = request.getHeader(CommonConstant.HEADER_OPENID);
			}
			if (openId == null || openId == "") {
				resultMap.put("flag", "0");
				resultMap.put("resultMsg", "请重新关注！");
			} else {
				// resultMap = customerService.insertCarOwner(CarOwnerDto,
				// openId);
				resultMap = customerService.register(CarOwnerDto, openId);
			}
			return new Response(ResultMsgConstants.RESULT_CODE_SUCCESS, resultMap, "");
		} catch (Exception e) {
			logger.info("Exception:", e);
			return new Response(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}

	}

	/**
	 * 更新验证码
	 * 
	 * @author QianKun
	 * @date 2017年3月8日
	 * @param memberDto
	 * @return
	 */
	@RequestMapping(value = "/updateCode", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "更新验证码", notes = "更新验证码")
	public @ResponseBody Response<Map<String, Object>> updateIdentifyingCode(@RequestBody @Valid MemberDto memberDto,
			HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<>();
		try {
			String openId = request.getHeader(CommonConstant.HEADER_OPENID);
			// String openId = "oXrcfuGP_a3daNZaMT_rbhvJ595I";
			// logger.info("准备发送验证码，获取OPEN_ID：" + openId);
			resultMap = customerService.updateIdentifyingCode(memberDto, openId);
			logger.info("验证码发送结束!");
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultMap, "");
		} catch (Exception e) {
			logger.info("Exception:", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}

	}

	/**
	 * 销售/售后顾问查询
	 * 
	 * @author QianKun
	 * @date 2016年12月14日
	 * @param dealerCode
	 * @param positionId
	 * @return
	 */
	@RequestMapping(value = "/counselors", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "销售/售后顾问查询", notes = "销售/售后顾问查询")
	public List<CounselorDto> getCounselorData(@RequestParam("dealerCode") String dealerCode,
			@RequestParam("positionId") String positionId) {
		List<CounselorDto> dtoList = customerService.getCounselorData(dealerCode, positionId);
		return dtoList;
	}

	/**
	 * 车主认证(绑车)
	 * 
	 * @author QianKun
	 * @date 2017年3月9日
	 * @param carInfoDto
	 * @return
	 */
	@RequestMapping(value = "/carInfo", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "车主认证(绑车)", notes = "车主认证(绑车)")
	public Response<Map<String, Object>> saveCarInfo(@RequestBody CarInfoDto carInfoDto,
			@RequestParam(value = "userId_", required = false, defaultValue = "") String userId_,
			HttpServletRequest request) {
		String userId = "";
		Map<String, Object> result;
		try {
			if (!CheckUtil.NullOrEmpty(userId_)) {
				userId = userId_;
			} else {
				userId = request.getHeader(CommonConstant.HEAD_USER_ID);
			}
			// result = customerService.saveCarInfo(carInfoDto, openId);
			result = customerService.bindingCar(carInfoDto, userId);
			logger.info(result);
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("车主认证发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 修改用户车子绑定状态
	 * 
	 * @param ownercarrelationdto
	 * @return
	 */
	@RequestMapping(value = "/updateCarinfoStu", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ResponseBody
	@ApiOperation(value = "修改用户车子绑定状态", notes = "修改用户车子绑定状态")
	public Map<String, Object> updateCarinfoStu(
			@RequestParam(value = "carId", required = true, defaultValue = "") String carId,
			@RequestParam(value = "userId_", required = false, defaultValue = "") String userId_,
			HttpServletRequest request) {
		String userId = "";
		if (!CheckUtil.NullOrEmpty(userId_)) {
			userId = userId_;
		} else {
			userId = request.getHeader(CommonConstant.HEAD_USER_ID);
		}
		return customerService.updateCarinfoStu(carId, userId);
	}

	@RequestMapping(value = "/updateCarinfo", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> updateCarinfo(@RequestBody CarInfoDto carinfodto) {
		Map<String, Object> map = customerService.updateCarinfo(carinfodto);
		return map;
	}

	/**
	 * 獲取保險公司
	 * 
	 * @author Administrator TODO description
	 * @date 2017年4月13日
	 * @return
	 */
	@RequestMapping(value = "/InsuranceMap", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	public List<InsuranceDto> getInsuranceMap() {
		return customerService.getInsuranceMap();
	}

	/**
	 * 微信关注
	 * 
	 * @author QianKun
	 * @date 2017年3月25日
	 * @param event
	 * @return
	 */
	@RequestMapping(value = "/event", method = RequestMethod.POST)
	@ApiOperation(value = "微信关注", notes = "接收事件进行微信消息推送")
	public MQReceiveResult receiveEvent(@RequestBody BizEvent event) {
		MQReceiveResult result = customerService.receiveEvent(event);
		return result;
	}

	/**
	 * 更改潜客DealerCode
	 * 
	 * @author Qiankun
	 * @date 2017年3月27日
	 * @param memberDto
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/dealerCode", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "更改会员DealerCode", notes = "更改会员DealerCode")
	public Response<Map<String, Object>> updateDealerCode(
			@RequestParam(required = false, defaultValue = "") String dealerCode, HttpServletRequest request) {
		logger.info("CustomerController.getMemberInfo==>start...");
		try {
			String userId = request.getHeader(CommonConstant.HEAD_USER_ID);
			logger.info("我的userId为：" + userId);
			customerService.updateDealerCode(dealerCode, userId);
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, new HashMap<>(), "");
		} catch (Exception e) {
			logger.error("查询发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		} finally {
			logger.info("CustomerController.getMemberInfo==>end...");
		}
	}

	/**
	 * 修改手机号(车主)
	 * 
	 * @date 2017年4月7日
	 * @param memberDto
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/updatePhone", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public @ResponseBody Map<String, Object> updatePhone(@RequestBody @Valid CarOwnerDto CarOwnerDto,
			HttpServletRequest request) {
		String openId = request.getHeader(CommonConstant.HEADER_OPENID);
		Map<String, Object> resultMap = customerService.updatePhone(CarOwnerDto, openId);
		return resultMap;
	}

	/**
	 * 个人资料查询
	 * 
	 * @author Administrator
	 * @date 2017年4月28日
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/customerInfo", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "查询个人资料", notes = "查询个人资料")
	public List<MemberDto> getCustomerInfo(HttpServletRequest request) {
		String openId = request.getHeader(CommonConstant.HEADER_OPENID);
		// String openId= "oXrcfuGP_a3daNZaMT_rbhvJ595I";
		logger.info("我的OPENID为：" + openId);
		List<MemberDto> dtoList = customerService.getCustomerInfo(openId);
		return dtoList;
	}

	/**
	 * 企业注册会员(车主)
	 * 
	 * @param CarOwnerDto
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/insertThirdCarOwner", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "企业注册会员(车主)", notes = "企业注册会员(车主)")
	public @ResponseBody Map<String, Object> insertThirdCarOwner(@RequestParam("openId") String openId,
			@RequestParam("phone") String phone, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<>();
		if (openId == null || openId == "") {
			resultMap.put("resultMsg", "请重新关注！");
		} else {
			resultMap = customerService.insertThirdCarOwner(openId, phone);
		}
		return resultMap;
	}

	/**
	 * 车主认证匹配销售店
	 * 
	 * @author Administrator
	 * @date 2017年6月1日
	 * @param latitude
	 * @param longitude
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/dealerInfo", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "车主认证匹配销售店", notes = "车主认证匹配销售店")
	public List<TmDealer> selectDealer(@RequestParam("regionName") String regionName,
			@RequestParam("latitude") String latitude, @RequestParam("longitude") String longitude,
			HttpServletRequest request) throws Exception {
		String openId = request.getHeader(CommonConstant.HEADER_OPENID);
		// String openId= "oXrcfuGP_a3daNZaMT_rbhvJ595I";
		logger.info("我的OPENID为：" + openId);
		List<TmDealer> resultList = new ArrayList<TmDealer>();
		logger.info("经纬度>>>>>>" + longitude + "," + latitude);
		TmDealer td = customerService.selectDealer(regionName, latitude, longitude, openId);
		logger.info("service返回结果>>>>>>>" + td.getDealerCode());
		resultList.add(td);
		return resultList;
	}

	/**
	 * 推送消息给某个用户
	 * 
	 * @author Administrator
	 * @date 2017年6月2日
	 * @param openId
	 * @param content
	 * @return
	 */
	@RequestMapping(value = "/messages", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "推送消息给用户", notes = "推送消息给用户")
	public void sendMessage(@RequestParam("openId") String openId,
			@RequestParam("content") String content) {
		customerService.sendMessage(openId, content);
	}

	/**
	 * 群发消息
	 * 
	 * @author Administrator
	 * @date 2017年6月2日
	 * @param openId_List
	 * @param content
	 * @return
	 */
	@RequestMapping(value = "/mass/message", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "群发消息", notes = "群发消息")
	public void mass(@RequestParam("openId_List") String openId_List,
			@RequestParam("content") String content) {
		customerService.mass(openId_List, content);
	}

	@RequestMapping(value = "/randomCode", method = RequestMethod.GET)
	@ApiOperation(value = "随机验证码", notes = "随机验证码")
	public Response<String> randomCode(HttpServletRequest request) {
		String result = "";
		String openId = request.getHeader(CommonConstant.HEADER_OPENID);
		// String openId= "oXrcfuGP_a3daNZaMT_rbhvJ595I";
		try {
			result = customerService.randomCode(openId);
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("Exception:", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 添加投诉信息
	 * 
	 * @date 2017年7月4日
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/addComplaint", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "用户投诉", notes = "用户投诉")
	public Response<Map<String, Object>> addComplaint(@RequestBody TtComplaint ttComplaint, HttpServletRequest request) {
		String openId = request.getHeader(CommonConstant.HEADER_OPENID);
		// String openId = "oXrcfuGP_a3daNZaMT_rbhvJ595I";
		Map<String, Object> result = new HashMap<>();
		try {
			result = customerService.addComplaint(openId, ttComplaint);
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 投诉类型
	 * 
	 * @date 2017年7月8日
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/queryComplaintType", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "投诉类型", notes = "投诉类型")
	public Response<List<Map<String, Object>>> queryComplaintType() {
		List<Map<String, Object>> result = new ArrayList<>();
		try {
			result = customerService.queryComplaintType();
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 首选店
	 * 
	 * @date 2017年7月8日
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryFirstDealer", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "首选店", notes = "首选店")
	public Response<Map<String, Object>> queryFirstDealer(HttpServletRequest request) {
		Map<String, Object> result = new HashMap<>();
		try {
			String openId = request.getHeader(CommonConstant.HEADER_OPENID);
			// String openId = "oXrcfuGP_a3daNZaMT_rbhvJ595I";
			logger.info("查询首选店开始，openId：" + openId);
			result = customerService.queryFirstDealer(openId);
			logger.info("查询首选店结束");
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 查询未工单评价个数
	 * 
	 * @param info
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryEvaluationNum", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "查询未工单评价个数", notes = "查询未工单评价个数")
	public Response<?> queryEvaluationNum(HttpServletRequest request) throws Exception {
		try {
			String openId = request.getHeader(CommonConstant.HEADER_OPENID);
			// String openId = "oXrcfuGP_a3daNZaMT_rbhvJ595I";
			logger.info("查询未工单评价个数开始openId：" + openId);
			Integer result = customerService.queryEvaluationNum(openId);
			logger.info("查询未工单评价个数结束");
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("Exception:", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 推送积分变更消息
	 * 
	 * @param info
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/sendPointsMessage", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "推送积分变更消息", notes = "推送积分变更消息")
	public MQReceiveResult sendPointsMessage(@RequestBody PointsChangePO pointsChangePO) throws Exception {
		logger.info("推送积分变更消息开始");
		Map<String, Object> resultMap = customerService.sendPointsMessage(pointsChangePO);
		MQReceiveResult result = new MQReceiveResult();
		if (Integer.valueOf(resultMap.get("flag").toString()) == 1
				|| Integer.valueOf(resultMap.get("flag").toString()).equals(1)) {
			result.setResult("200");
			result.setMessage(resultMap.get("msg").toString());
			logger.info("返回参数：200" + resultMap.get("msg").toString());
		} else {
			result.setResult("500");
			result.setMessage("推送积分变更消息出错！");
			logger.info("推送积分变更消息出错！");
		}
		logger.info("推送积分变更消息结束");
		return result;
	}

	/**
	 * 批量推送积分变更消息
	 * 
	 * @param info
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/sendBatchPoints", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "批量推送积分变更消息", notes = "批量推送积分变更消息")
	public MQReceiveResult sendBatchPoints(@RequestBody List<PointsChangePO> pointsChangeList) throws Exception {
		logger.info("批量推送积分变更消息开始");
		Map<String, Object> resultMap = customerService.sendBatchPoints(pointsChangeList);
		MQReceiveResult result = new MQReceiveResult();
		if (Integer.valueOf(resultMap.get("flag").toString()) == 1
				|| Integer.valueOf(resultMap.get("flag").toString()).equals(1)) {
			result.setResult("200");
			result.setMessage(resultMap.get("msg").toString());
			logger.info("返回参数：200" + resultMap.get("msg").toString());
		} else {
			result.setResult("500");
			result.setMessage("推送积分变更消息出错！");
			logger.info("批量推送积分变更消息出错！");
		}
		logger.info("批量推送积分变更消息结束");
		return result;
	}

	/***
	 * 跟踪客户端异常，方便以后BUG重现
	 * 
	 * @param map
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/trackBehavior", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "客户端异常跟踪", notes = "客户端异常跟踪")
	public Response<?> trackUserBehavior(@RequestBody Map<String, Object> map, HttpServletRequest request)
			throws Exception {
		TtWebpageLog ttWebpageLog = new TtWebpageLog();
		List<TtWebpageLog> insertList = new ArrayList<TtWebpageLog>();
		String openId = request.getHeader(CommonConstant.HEADER_OPENID);
		try {
			ttWebpageLog.setOpenId(openId);
			ttWebpageLog.setContent(map.get("errMsg").toString());
			ttWebpageLog.setPhoneModel(map.get("userAgent").toString());
			ttWebpageLog.setRoute(map.get("currentUrl").toString());
			insertList.add(ttWebpageLog);
			int num = webpageLogService.addWebpageLog(insertList);
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, num, "");
		} catch (Exception e) {
			// handle exception
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, "", e.getMessage());
		}

	}

	@RequestMapping(value = "/trackBehavior/list", method = RequestMethod.GET)
	@ApiOperation(value = "客户端异常跟踪列表", notes = "客户端异常跟踪列表")
	public Response<PageInfo<WebpageLogPo>> getWebpageLogList(
			@RequestParam(required = false, defaultValue = "0") Integer pageNum,
			@RequestParam(required = false, defaultValue = "create_date") String sort,
			@RequestParam(required = false, defaultValue = "desc") String sortType,
			@RequestParam(required = false, defaultValue = "10") String pageSize) throws Exception {
		try {
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("pageNum", pageNum);
			paramMap.put("pageSize", pageSize);
			paramMap.put("sort", sort);
			paramMap.put("sortType", sortType);
			PageInfo<WebpageLogPo> resultMap = webpageLogService.getWebpagLog(paramMap);
			return new Response<PageInfo<WebpageLogPo>>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultMap, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	@RequestMapping(value = "/birthday", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "推送生日祝福给用户", notes = "推送生日祝福给用户")
	public Map<String, Object> sendBirthday() throws Exception {
		Map<String, Object> resultMap = new HashMap<>();
		resultMap = customerService.sendBirthday();
		logger.info("返回结果>>>>>>>>>" + resultMap);
		return resultMap;
	}
	
	
	/**
     * 重新获取微信用户信息
     * @param request
     * @return
	 * @throws Exception 
     */
    @RequestMapping(value = "/getWXUserAgain", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "重新获取微信用户信息", notes = "重新获取微信用户信息")
    public String getWXUserAgain(HttpServletRequest request) throws Exception{
    	logger.info("重新获取微信用户信息开始");
    	String openId = request.getHeader(CustomerInfoConstant.HEADER_OPENID);
    	//String openId = "oXrcfuCpMJXvTH9L38ajQmEuaoxw";
    	//String openId = "oXrcfuCQdZFp-HjG6aBG4TQxuPnw";
    	logger.info("重新获取微信用户信息开始，获取的openId为："+openId);
        String result = customerService.getWXUserAgain(openId);
        logger.info("重新获取微信用户信息完成" + result);
        return result;
    }

}
